//
//  SetupTableViewController.m
//  FlyGift
//
//  Created by lanou3g on 15/7/11.
//  Copyright (c) 2015年 lanou3g. All rights reserved.
//


#import "SetupTableViewController.h"
#import "OpinionViewController.h"
#import "AboutViewController.h"

@interface SetupTableViewController ()
@property(nonatomic,strong)NSArray *setupArray0;
@property(nonatomic,strong)NSArray *setupArray1;
@end

@implementation SetupTableViewController


- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.navigationController.navigationBar.translucent = NO;
    self.navigationItem.title = @"设置";
    self.view.backgroundColor = [UIColor purpleColor];
    
    self.tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, kScreenWidth, kScreenHeight - 64) style:UITableViewStyleGrouped];
    
    self.tableView.separatorStyle = UITableViewCellAccessoryNone;
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    
    return 3;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    
    if (section == 0)
    {
        return 3;
    }
    if (section == 1)
    {
        return 3;
    }
    else
    {
        return 1;
    }
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *dentifier = @"cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:dentifier];
    if (cell == nil)
    {
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:dentifier];
    }
    cell.backgroundColor = [UIColor whiteColor];
    //取消你所点击的cell的背景颜色 (在没有设置这个之前 你点击cell后 cell的背景会变成灰色)
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    
    self.setupArray0 = @[@"向好友推荐飞礼~",@"给我们评分吧",@"意见反馈"];
    self.setupArray1 = @[@"接收消息提醒",@"夜间模式开关",@"清除缓存"];
    
    if (indexPath.section == 0)
    {
        for (int i = 0; i < _setupArray0.count; i++)
        {
            if (indexPath.row == i)
            {
            cell.imageView.image = [UIImage imageNamed:@"recommend"];
            cell.textLabel.text = _setupArray0[i];
                cell.textLabel.font = [UIFont systemFontOfSize:14];
        }
            if (indexPath.row == 2)
            {
                cell.accessoryType =   UITableViewCellAccessoryDisclosureIndicator;
                UILabel *line = [[UILabel alloc]initWithFrame:CGRectMake( 0, kP6Height(44), kP6width(280), kP6Height(1))];
                line.backgroundColor = [UIColor blackColor];
                line.alpha = 0.1;
                [cell addSubview:line];
            }
            else
            {
                UILabel *line = [[UILabel alloc]initWithFrame:CGRectMake( kP6width(50), kP6Height(44), kP6width(280), kP6Height(1))];
                line.backgroundColor = [UIColor blackColor];
                line.alpha = 0.1;
                [cell addSubview:line];
            }
    }
}
   else if (indexPath.section == 1)
    {
        for (int i = 0; i < _setupArray1.count; i++)
        {
            if (indexPath.row == i)
            {
                cell.imageView.image = [UIImage imageNamed:@"recommend"];
                cell.textLabel.text = _setupArray1[i];
                cell.textLabel.font = [UIFont systemFontOfSize:14];
            }
            if (indexPath.row == 2)
            {
                cell.accessoryType =   UITableViewCellAccessoryDisclosureIndicator;
                UILabel *line = [[UILabel alloc]initWithFrame:CGRectMake( 0, kP6Height(44), kP6width(280), kP6Height(1))];
                line.backgroundColor = [UIColor blackColor];
                line.alpha = 0.1;
                [cell addSubview:line];
            }
            else
            {
                UILabel *line = [[UILabel alloc]initWithFrame:CGRectMake( kP6width(50), kP6Height(44), kP6width(280), kP6Height(1))];
                line.backgroundColor = [UIColor blackColor];
                line.alpha = 0.1;
                [cell addSubview:line];
            }
            if (indexPath.row != 2)
            {
                //创建 UISwitch  (就是开关键)
                UISwitch *mySwitch = [[UISwitch alloc]initWithFrame:CGRectMake(kP6width(280-60), kP6Height(7.5), kP6width(50), kP6Height(20))];
                //设置UISwitch的初始化状态  (默认是 NO 的这一次边)
                mySwitch.on = YES;
                [cell addSubview:mySwitch];

            }
        }
    }
    else
    {
        cell.accessoryType =   UITableViewCellAccessoryDisclosureIndicator;
        cell.textLabel.text = @"关于飞礼";
        cell.imageView.image = [UIImage imageNamed:@"icon_loading_action1"];
        
        UILabel *line = [[UILabel alloc]initWithFrame:CGRectMake( 0, 0, kP6width(280), kP6Height(1))];
        line.backgroundColor = [UIColor blackColor];
        line.alpha = 0.1;
        [cell addSubview:line];
        
        UILabel *line1 = [[UILabel alloc]initWithFrame:CGRectMake( 0, kP6Height(44), kP6width(280), kP6Height(1))];
        line1.backgroundColor = [UIColor blackColor];
        line1.alpha = 0.1;
        [cell addSubview:line1];
        
    }
    
    return cell;
}


-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 44;
}

// 点击cell 的触发事件
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section == 0)
    {
        if (indexPath.row == 0)
        {
            NSLog(@"点击了 向好友推荐礼物说");
        }
        
        else if (indexPath .row == 1)
        {
            NSLog(@"点击了 给我们评分吧");
        }
        
        // 点击 意见反馈 跳转界面
        else if (indexPath.row == 2)
        {
            OpinionViewController *opinion = [[OpinionViewController alloc]init];
            [self.navigationController pushViewController:opinion animated:YES];
        }
    }
    else if (indexPath.section == 1)
    {
        if (indexPath.row == 0)
        {
            NSLog(@"点击了 接收消息提醒");
        }
        else if (indexPath.row == 1)
        {
            NSLog(@"点击了 夜间模式开关");
        }
        else if (indexPath.row == 2)
        {
            NSLog(@"点击了 清除缓存");
        }
    }
    else
    {
        AboutViewController *about = [[AboutViewController alloc]init];
        [self.navigationController pushViewController:about animated:YES];
    }
}




@end
